1 //+-----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // Defines the PersistHistory class of PresentationHost.
12 // Ported Windows->DevDiv. See SourcesHistory.txt.
14 //------------------------------------------------------------------------
16 #include "Precompiled.hxx"
17 #include "PersistHistory.hxx"
18 #include "HostShim.hxx"
19 #include "Version.hxx"
21 // This macro will keep the types in [....] between the LoadHistoryHelper and SaveHistoryHelper methods.
22 #define STARTUP_URI_LENGTH_TYPE ULONG
24 /******************************************************************************
25 CPersistHistory::CPersistHistory()
26 ******************************************************************************/
27 CPersistHistory::CPersistHistory(CHostShim
*pHostShim
)
29 m_pHostShim
= pHostShim
;
32 /******************************************************************************
33 CPersistHistory::~CPersistHistory()
34 ******************************************************************************/
35 CPersistHistory::~CPersistHistory()
39 /******************************************************************************
40 CPersistHistory::QueryInterface()
41 ******************************************************************************/
42 STDMETHODIMP
CPersistHistory::QueryInterface(REFIID riid
, LPVOID
*ppReturn
)
44 return m_pHostShim
->QueryInterface(riid
, ppReturn
);
47 /******************************************************************************
48 CPersistHistory::AddRef()
49 ******************************************************************************/
50 STDMETHODIMP_(ULONG
) CPersistHistory::AddRef()
52 return m_pHostShim
->AddRef();
55 /******************************************************************************
56 CPersistHistory::Release()
57 ******************************************************************************/
58 STDMETHODIMP_(ULONG
) CPersistHistory::Release()
60 return m_pHostShim
->Release();
63 /******************************************************************************
64 CPersistHistory::GetClassID()
65 ******************************************************************************/
66 STDMETHODIMP
CPersistHistory::GetClassID(LPCLSID pClassID
)
68 return m_pHostShim
->GetClassID(pClassID
);
71 /******************************************************************************
72 CPersistHistory::SetPositionCookie
73 ******************************************************************************/
74 STDMETHODIMP
CPersistHistory::SetPositionCookie(DWORD
/*dwPositionCookie*/)
79 /******************************************************************************
80 CPersistHistory::GetPositionCookie
81 ******************************************************************************/
82 STDMETHODIMP
CPersistHistory::GetPositionCookie(__out DWORD
* pdwPositionCookie
)
86 CK_PARG(pdwPositionCookie
);
88 *pdwPositionCookie
= 0;
95 /**************************************************************************
96 CPersistHistory::SaveHistory(IStream *pStream)
97 **************************************************************************/
98 STDMETHODIMP
CPersistHistory::SaveHistory(__in IStream
* pSaveStream
)
102 CKHR(m_pHostShim
->RequestedVersion()->WriteToStream(pSaveStream
));
103 CKHR(WriteToStream(pSaveStream
, (DWORD
) m_pHostShim
->GetMimeType()));
104 CKHR(m_pHostShim
->StartupUri()->WriteToStream(pSaveStream
));
105 CKHR(m_pHostShim
->StartupLocation()->WriteToStream(pSaveStream
));
106 CKHR(m_pHostShim
->ApplicationIdentity()->WriteToStream(pSaveStream
));
108 if(!m_pHostShim
->GetVersion())
112 CKHR(m_pHostShim
->GetVersion()->SaveToHistory(pSaveStream
));
118 /**************************************************************************
119 CPersistHistory::LoadHistory(IStream *pStream, IBindCtx *pbc)
120 **************************************************************************/
121 STDMETHODIMP
CPersistHistory::LoadHistory(__in IStream
* pLoadStream
, IBindCtx
* pBindCtx
)
125 // When doing navigations inside of an app, history is saved without going through
126 // CPersistHistory::SaveHistory, so the information that puts in the stream isn't there.
127 // This check is to be sure that we are being activated by IPersistHistory.
129 if (!m_pHostShim
->GetVersion())
131 CKHR(m_pHostShim
->RequestedVersion()->ReadFromStream(pLoadStream
));
134 CKHR(ReadFromStream(pLoadStream
, &mimeType
));
135 m_pHostShim
->SetMimeType((MimeType
)mimeType
);
137 CKHR(m_pHostShim
->StartupUri()->ReadFromStream(pLoadStream
));
138 CKHR(m_pHostShim
->StartupLocation()->ReadFromStream(pLoadStream
));
139 CKHR(m_pHostShim
->ApplicationIdentity()->ReadFromStream(pLoadStream
));
141 pLoadStream
->AddRef();
142 m_pHostShim
->SetHistoryStream(pLoadStream
);
144 m_pHostShim
->Execute(); //[Watson on error]
147 CKHR(m_pHostShim
->GetVersion()->LoadFromHistory(pLoadStream
, pBindCtx
));
153 STDMETHODIMP
CPersistHistory::ReadFromStream(IStream
* pInputStream
, DWORD
* pdwData
)
157 CHECK_POINTER(pdwData
);
160 CKHR(pInputStream
->Read((void*)pdwData
, sizeof(*pdwData
), &bytesRead
));
166 STDMETHODIMP
CPersistHistory::WriteToStream(IStream
* pOutputStream
, DWORD dwData
)
170 ULONG bytesWritten
= 0;
171 CKHR(pOutputStream
->Write((void*)&dwData
, sizeof(dwData
), &bytesWritten
));